package bio.four;

import java.io.DataInput;
import java.io.DataInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.Socket;

public class HandlerFileThread extends Thread {
    private Socket socket;

    public HandlerFileThread(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        try (
                //获取数据输入流
                DataInputStream dis = new DataInputStream(socket.getInputStream());
        ) {
            //读取文件后缀
            String suffix = dis.readUTF();
            //写出文件
            FileOutputStream fos = new FileOutputStream("E:\\mycode\\io\\src\\1" + suffix);
            //读取文件
            byte[] buf = new byte[1024];
            int len = 0;
            while ((len = dis.read(buf)) != -1) {
                fos.write(buf, 0, len);
            }
            fos.flush();
            fos.close();
        } catch (Exception e) {
            e.getStackTrace();
        }
    }
}
